def merge_and_deduplicate_files(file1, file2, file3, file4):
    # 读取所有文件内容
    files = [file1, file2, file3, file4]
    all_lines = set()

    # 从每个文件中读取内容并添加到集合中（去重）
    for file in files:
        with open(file, 'r') as f:
            lines = f.readlines()
            all_lines.update([line.strip() for line in lines])

    # 将去重后的内容按时间戳排序
    sorted_lines = sorted(all_lines, key=lambda x: float(x.split()[0]))

    # 将去重后的内容写入第一个文件
    with open(file1, 'w') as f:
        f.write('\n'.join(sorted_lines))
    print(f"合并和去重后的内容已保存到 {file1}")


# 替换为你的文件名
merge_and_deduplicate_files('E:\data\data_0905/room/rgb.txt', 'E:\data\data_09051/room/rgb.txt', 'E:\data\data_09052/room/rgb.txt', 'E:\data\data_09053/room/rgb.txt')
